package com.atguigu.tingshu.album.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.annotation.login.LoginRequired;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory3;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 分类管理
 * @author sun
 *
 */
@RestController
@RequestMapping(value="/api/album/category")
public class BaseCategoryController {
	
	@Resource
	private BaseCategoryService baseCategoryService;

	/**
	 * 获取专辑的分类
	 * @return 分类信息列表
	 */
	@GetMapping(value="/getBaseCategoryList")
	@LoginRequired
	public Result<List<JSONObject>> getBaseCategoryList() {
		return Result.ok(baseCategoryService.getBaseCategoryList());
	}

	/**
	 * 根据一级分类分类id获取标签
	 * @param category1Id 一级分类id
	 * @return 标签列表
	 */
	@GetMapping("/findAttribute/{category1Id}")
	@LoginRequired
	public Result<List<BaseAttribute>> findAttribute(@PathVariable("category1Id") Long category1Id) {
		List<BaseAttribute> result = baseCategoryService.findAttribute(category1Id);
		return Result.ok(result);
	}


	/**
	 * 根据一级分类idTOP7的三级分类
	 * @param category1Id 一级分类id
	 * @return 三级分类
	 */
	@GetMapping("/findTopBaseCategory3/{category1Id}")
	@LoginRequired
	public Result<List<BaseCategory3>> findTopBaseCategory3(@PathVariable("category1Id") Long category1Id){
		return Result.ok(baseCategoryService.findTopBaseCategory3(category1Id));
	}

	/**
	 * 根据一级分类查询所有的二级和三级分类
	 * @param category1Id 一级分类id
	 * @return 二级和三级分类
	 */
	@GetMapping("/getBaseCategoryList/{category1Id}")
	@LoginRequired
	public Result<JSONObject> getBaseCategoryList(@PathVariable("category1Id") Long category1Id){
		return Result.ok(baseCategoryService.getBaseCategoryListById(category1Id));
	}


}

